package com.example.zhu.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhu.dto.Student;
import com.example.zhu.Mapper.StudentMapper;
import com.example.zhu.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Autowired
    private StudentMapper studentmapper;

    @Override
    public void updateData(Student student1) {
        studentmapper.updateById(student1);
    }

    @Override
    public Student getstudent() {
        //构造条件构造器
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(Student::getState, 0).last("limit 1 FOR UPDATE");
        Student student = studentmapper.selectOne(queryWrapper);
        //执行查询
        return student;
    }
}
